<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/static/js/jquery-3.4.1.js"></script>
</head>
<body>
<div>
    <table border="1">
        <thead>
        <tr>
            <th>序号</th>
            <th>实验室</th>
            <th>楼层</th>
            <th>门牌号</th>
            <th>负责人</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for foo in laboratory_obj %}
            <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ foo.l_name }}</td>
                <td>{{ foo.layer_num }}</td>
                <td>{{ foo.room_num }}</td>
                <td>{{ foo.lab_manage }}</td>
                <td>
                    <button class="del" url='/laboratory_del/?id={{ foo.id }}'>删除</button>
                    <button><a href="/laboratory_alter/?id={{ foo.id }}">修改</a></button>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
<a href="/laboratory_add/">添加</a>
<script src="/static/js/sweetalert.min.js"></script>
<script>
    $('.del').click(function () {
        var _this = $(this);
        swal({
            title: "确认删除?",
            text: "一旦删除，文件将无法恢复!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((willDelete) => {
                if (willDelete) {

                    $.ajax({
                        url: _this.attr('url'),
                        type: 'get',
                        success: (res) => {
                            if (res.status === 200) {
                                swal("文件已被删除!", {
                                    icon: "success",
                                });
                                _this.parent().parent().remove()
                            } else {
                                swal("文件未删除!");
                            }
                        }
                    })
                } else {
                    swal("文件未删除!");
                }
            }
        );
    });
</script>
</body>
</html>

